package com.wen.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wen.mapper.CartMapper;
import com.wen.pojo.Cart;
import com.wen.pojo.dto.ProductAndCart;
import com.wen.service.CartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xie
 */
@Slf4j
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements CartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<ProductAndCart> getProductAndCart(String id) {
        return cartMapper.selProductAndCart(id);
    }

    @Override
    public int getProductAndCartCount(String id) {

        return cartMapper.selProductAndCartCount(id);
    }

    @Override
    public List<ProductAndCart> getProductAndCartSelected(String id) {
        return cartMapper.selProductAndCartSelected(id);
    }

    @Override
    public ProductAndCart getProductAndCartSum(String id) {
        return cartMapper.selProductAndCartSum(id);
    }

    @Override
    public int getUpdateCount(String count, Integer pid) {

        return cartMapper.UpdateCount(count,pid);
    }

    @Override
    public int getUpdateSelected(String id,Integer sed) {
        Cart cart = new Cart();
        cart.setSelected(sed);
        QueryWrapper<Cart> qw = new QueryWrapper<>();
        qw.lambda().eq(Cart::getId,id);

        return cartMapper.update(cart,qw);
    }


}
